package com.wss.service.impl;

import com.wss.dao.BlogDao;
import com.wss.dao.CommentDao;
import com.wss.domain.Blog;
import com.wss.domain.Comment;
import com.wss.domain.Message;
import com.wss.service.BlogService;
import com.wss.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("commentService")
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentDao commentDao;

    @Override
    public List<Comment> findCommentAll() {
        System.out.println("业务层：查询所有评论...");
        List<Comment> blogCommentList = commentDao.findBlogCommentAll();
        List<Comment> videoCommentList = commentDao.findVideoCommentAll();
        // 将两条评论list放入一个
        List<Comment> commentList = new ArrayList<Comment>();
        commentList.addAll(blogCommentList);
        commentList.addAll(videoCommentList);
        return commentList;
    }

    @Override
    public List<Comment> findCommentByBlogId(int b_id) {
        System.out.println("业务层：根据博客id查询评论...");
        return commentDao.findCommentByBlogId(b_id);
    }

    @Override
    public List<Comment> findCommentByVideoId(int v_id) {
        System.out.println("业务层：根据视频id查询评论...");
        return commentDao.findCommentByVideoId(v_id);
    }

    @Override
    public Message addComment(Comment comment) {
        System.out.println("业务层：添加评论...");
        Message message = new Message();
        int res = commentDao.addComment(comment);
        if (res > 0){
            message.setResCode(1);
            message.setResultMsg("发表成功");
        }else{
            message.setResCode(0);
            message.setResultMsg("发表失败");
        }
        return message;
    }

    @Override
    public Message deleteComment(Comment comment) {
        System.out.println("业务层：删除评论...");
        Message message = new Message();
        int res = commentDao.deleteComment(comment);
        if (res > 0){
            message.setResCode(1);
            message.setResultMsg("删除成功");
        }else{
            message.setResCode(0);
            message.setResultMsg("删除失败");
        }
        return message;
    }
}
